package com.zw.controller;

import com.zw.utils.OssUploader;
import com.zw.vo.ResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RequestMapping("pic/upload")
@Controller
@Api(value = "文件上传API", tags = "文件上传API")
public class PicUploadController {

    @Autowired
    private OssUploader ossUploader;
    @PostMapping
    @ResponseBody
    @ApiOperation("文件上传")
    public ResponseVO upload(@RequestParam("files") MultipartFile[] files)  throws IOException {
        try {
            List<String> urls = ossUploader.uploadPdfFiles(files);
            return new ResponseVO(urls);
        } catch (IllegalArgumentException e) {
            throw new RuntimeException(e.getMessage());
        } catch (Exception e) {
            throw new RuntimeException("上传失败");
        }
    }
}
